<template>
  <el-dialog append-to-body title="分配角色" :visible="showRoleDialog" @close="hClose">
    <!--  -->
    <p>{{ curId }}</p>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="btnOK">确定</el-button>
      <el-button @click="hClose">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { assignRoles, getEmployeeDetail, getEnableRoleList } from '@/api/employee'
export default {
  props: {
    showRoleDialog: {
      type: Boolean,
      required: true
    },
    curId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      roleList: []
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    async btnOK() {
      await assignRoles({ id: this.curId, roleIds: this.roleIds })
      //   console.log(res)
      this.$message.success('保存成功')
      this.hClose()
    },
    hClose() {
      this.$emit('update:showRoleDialog', false)
    },
    async getRoleList() {
      const res = await getEnableRoleList()
      //   console.log(res)
      this.roleList = res.data
    },
    async getRoleUser() {
      const res = await getEmployeeDetail(this.curId)
      //   console.log(res)
      this.roleIds = res.data.roleIds
    }
  }

}
</script>

<style>

</style>
